package test

import bankofficegrepper.BankInfoWriter
import bankofficegrepper.ICBCBankInfoResolver
import com.jleo.BankInfoBuffer
import module.ICBCMainPageModule
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.telluriumsource.test.java.TelluriumJUnitTestCase

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2010-11-20
 * Time: 13:50:54
 * To change this template use File | Settings | File Templates.
 */
class ICBCTestCase extends TelluriumJUnitTestCase {
  private static ICBCMainPageModule icbcMain
  private static BankInfoBuffer buffer

  @BeforeClass
  public static void initUi() {
    buffer = new BankInfoBuffer()
    icbcMain = new ICBCMainPageModule(buffer)
    icbcMain.defineUi();
    icbcMain.defineUi();

    //icbcMain.disableCssSelector()
    //useTelluriumEngine(true);
  }

  @Before
  public void connectToPage() {
    connectSeleniumServer()
    connectUrl 'http://www.icbc.com.cn/icbc/%E5%8A%9F%E8%83%BD%E4%BC%98%E5%8C%96/%E7%BD%91%E7%82%B9%E6%9F%A5%E8%AF%A2/%E7%BD%91%E7%82%B9%E4%BF%A1%E6%81%AF%E5%88%97%E8%A1%A8.htm?&siteArea=AreaInfo;2e7114ec-323c-4954-8e3f-38f4ba2a5ff0&CityId=&siteStyle=&site_KeyWord='
  }

  //Add your test cases here

  @Test
  public void testMain() {
    def allBankInfo = []
    Thread comsumer = new Thread(new Runnable() {
      void run() {
        while (!buffer.produceFinish || buffer.size > 0) {
          allBankInfo.addAll new ICBCBankInfoResolver().resolveData(buffer.consume())
        }
        new BankInfoWriter("icbc.txt").writeTo(allBankInfo)
      }
    }).start()
    icbcMain.getAllProvinceNames().each {
      icbcMain.selectProvince(it)
    }
    buffer.produceFinish = true

//        allBankInfo.addAll(bankInfos)

  }
}
